package com.dckeji.shiplock.webapp.dao.impl;

import com.dckeji.shiplock.webapp.dao.IPayDao;
import com.dckeji.shiplock.webapp.pojo.Pay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: TianWei
 * Date: 2017/8/8
 * Time: 11:49
 */
@Repository
public class PayDaoImpl implements IPayDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int commitPayVoucher(String shipNo, String imgKey, String commitTime) {
        String sql = "INSERT INTO pay (shipNo,vouCherUrl,commitTime) values(?,?,?)";
        return jdbcTemplate.update(sql, new Object[]{shipNo, imgKey, commitTime});
    }

    @Override
    public List<Pay> query(String shipNo, Integer status) {

        String sql = "select vouCherUrl,commitTime,examineTime from pay where shipNo=? and isExamine=?";

        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<Pay>(Pay.class), new Object[]{shipNo, status});
    }

    @Override
    public List<Pay> queryAll() {
        String sql = "select * from pay  where isExamine = 0 limit 30";

        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<Pay>(Pay.class));
    }

    @Override
    public int updatePayStatus(Integer declaId, Integer optType, String updateTime) {
        String sql = "update pay set examineTime=? ,commitTime=? `desc`=? where payId=?";

        return jdbcTemplate.update(sql, new Object[]{declaId, optType, updateTime});
    }
}
